<!DOCTYPE html>
<html xmlns:th="http://www.thymeleaf.org">
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>主页</title>
    <script src="js/jquery/jquery-3.4.1.min.js"></script>
</head>
<style>
    .header{
        width: auto;
        height: 80px;
        background-color: lightskyblue;
    }

    .title{
        color: white;
        float: left;
        margin-left: 20px;
    }

    .header:after .content:after{
        clear: both;
    }

    .search {
        width: 100%;
        display: flex;
    }

    .searchTerm {
        width: 70%;
        border: 3px solid #25b6c4;
        padding: 5px;
        height: 20px;
        border-radius: 5px 0 0 5px;
        outline: none;
        color: #16e1e1;
    }

    .searchTerm:focus{
        color: #25b6c4;
    }


    /* 下拉按钮样式 */
    .dropbtn {
        background-color: rgba(224, 222, 222, 0.6);
        color: black;
        padding: 16px;
        border: none;
        font-size: 16px;
        cursor: pointer;
        border-radius: 2px;
        width: 155px;
    }

    .dropdown {
        position: relative;
        display: inline-block;
        margin-left: 10%;
        margin-top: 10px;
    }

    /* 下拉内容*/
    .dropdown-content {
        /* 默认隐藏*/
        display: none;
        position: absolute;
        background-color: #f9f9f9;
        min-width: 160px;
        box-shadow: 0px 8px 16px 0px rgba(0,0,0,0.2);
    }

    /* 下拉菜单的链接 */
    .dropdown-content a {
        color: black;
        padding: 12px 16px;
        text-decoration: none;
        display: block;
    }

    /* 鼠标移上去后修改下拉菜单链接颜色 */
    .dropdown-content a:hover {background-color: #f1f1f1}

    /* 在鼠标移上去后显示下拉菜单 */
    .dropdown:hover .dropdown-content {
        display: block;
    }

    /* 下拉内容显示时下拉按钮的颜色需要改变*/
    .dropdown:hover .dropbtn {
        background-color: #82bbee;
    }

    .dropbtn2,.createbnt{
        color: #8a8a8a;!important;
        white-space: pre;
        font-size: 18px;!important;
    }


    .createbnt{
        margin-left: 50%;
    }

    .createbnt:before{
        content: url("img/添加收件夹.png");
    }
</style>
<body>
<div class="main">
    <span>
        由于没有域名，不能使用回调
    </span>
    <div class="content">
        <a class="dropbtn createbnt" target="_blank" href="/baidu_oauth">点击登录百度网盘</a>
    </div>
    <input id="code" type="text" class="searchTerm" placeholder="授权码"><br>
    <button type="submit" onclick="submitCode()" style="width: 100px;font-size: 20px;color: #6c4aa1"> 确定
    </button>
</div>
</body>
<script>
    function submitCode(){
        var code = $("#code").val()
        $.ajax({
            url:"/submit_code",
            data:{
                code: code
            },success(res){
                if(res["res"] == "user_error"){
                    alert("请登录")
                    location.href = "/login"
                }else if(res["res"] == "net_error"){
                    alert("网络错误，请重试")
                    location.reload()
                }else if(res["res"] == "token_error"){
                    alert("获取错误，请重试")
                    location.reload()
                }else if(res["res"] == "info_error"){
                    alert("获取用户信息错误，请重试")
                    location.reload()
                }else if(res["res"] == "pan_repeat"){
                    alert("重复绑定")
                    location.href = "/driver"
                }else{
                    location.href = "/driver"
                }
            },error(e){
                alert("网络错误，请重试")
                location.reload()
            }
        })
    }
</script>
</html>